
        <!DOCTYPE html>
        <html lang="en">
        <head>
            <meta charset="UTF-8">
            <meta http-equiv="X-UA-Compatible" content="IE=edge">
            <meta name="viewport" content="width=device-width, initial-scale=1.0">
            <title>Document</title>
        </head>
        <body>
            <section>
                <!-- &quot;      ____                       ______       &quot; -->
<!-- &quot;     &#x2F; __ ____ _____ ____      &#x2F;_  __&#x2F;____   &quot; -->
<!-- &quot;    &#x2F; &#x2F;_&#x2F; &#x2F; __ `&#x2F; __ `&#x2F; _ ______&#x2F; &#x2F; &#x2F; ___&#x2F;   &quot; -->
<!-- &quot;   &#x2F; ____&#x2F; &#x2F;_&#x2F; &#x2F; &#x2F;_&#x2F; &#x2F;  __&#x2F;_____&#x2F; &#x2F; &#x2F; &#x2F;       &quot; -->
<!-- &quot;  &#x2F;_&#x2F;    __,_&#x2F;__, &#x2F;___&#x2F;     &#x2F;_&#x2F; &#x2F;_&#x2F;        &quot; -->
<!-- &quot;              &#x2F;____&#x2F;                          &quot; -->
<!-- &quot;                                              &quot; -->
<br/><br/>
  <p>
    <span>Ubuntu下连接WiFi</span>
    <span>在Ubuntu终端下连接WiFi</span>
    <span>Ubuntu下连接WiFi</span>
  </p>
<b>NAME</b>
    <section style="margin-left:8%;">
    <strong>Ubuntu下连接WiFi</strong>
    - This is generated by page-tr
<br/><br/>
    本教程具有通用性，可以在大多数旧发行版和将来发行版的Linux发行版上很好地工作。 它也可以在WPA&#x2F;WPA2无线网络上正常工作。
    这些是在Linux命令行终端中连接到无线网络所需的工具。
<br/><br/>
    准备工具:
        <section style="margin-left:4%">
    ping, ip, iw, wpa_supplicat
        </section>
<br/><br/>
    iw:
        <section style="margin-left:4%">
    它是适用于所有无线设备的新的基于802.11的CLI配置实用程序。 它支持最近添加到内核的所有新驱动程序。
        </section>
<br/><br/>
    ip:
        <section style="margin-left:4%">
    它代表Internet协议。 它是Linux中的实用程序，用于测试和显示路由，设备，策略路由和隧道。
        </section>
<br/><br/>
    Linux WPA&#x2F;WPA2&#x2F;IEEE 802.1X SUPPLICANT:
        <section style="margin-left:4%">
    请求方是客户端站上使用的IEEE 802.1X &#x2F; WPA组件。 其目的是使用WPA身份验证和控制漫游以及IEEE 802.11身份验证和关联Wlan驱动程序来实现密钥协商。
        </section>
<br/><br/>
    ping:
        <section style="margin-left:4%">
    用于测试目标主机是存活还是死亡的实用程序。 它使用ICMP回显消息。
        </section>
<br/><br/>
    </section>
<b>SYNOPSIS</b>
    <section style="margin-left:8%;">
    Ubuntu下连接WiFi
<pre style="color:indianred">
    iw dev                  --- 查看WiFi适配器
    ip link show            --- 查看适配器状态
    ip link set wlan0 up    --- 启动wlan0适配器
    iw wlan0 link           --- 检查连接状态
    iw wlan0 scan           --- 使用适配器扫描WLAN
    wpa_passphrase          --- 生成wpa_supplicant设备连接配置WPA&#x2F;WPA2配置文件
    wpa_supplicant          --- 无线适配器WLAN连接工具
    dhclient wlan0          --- 从dhcp服务器获取ip地址
    ip route                --- 配置路由规则
    ping                    --- 检查链路是否正常

1.与Linux中的终端的WiFi连接
2.如何在Linux中轻松连接到WiFi
3.使用终端连接到WPA无线网络。
</pre>
    </section>
<b>STEPS:</b>
    <section style="margin-left:8%;">
    <strong>步骤1：查找所有可用的Wifi和适配器。</strong>
        <section style="margin-left:4%">
    首先使用iw命令查找所有可用的Wifi和适配器
<pre style="color:indianred">
    ubuntu@ubuntu:~$ iw dev
    phy#1
        Interface wlxe84e062972c6
            ifindex 4
            wdev 0x100000001
            addr e8:4e:06:29:72:c6
            type managed
            txpower 20.00 dBm
    phy#0
        Interface wlxe84e06355627
            ifindex 3
            wdev 0x1
            addr e8:4e:06:35:56:27
            ssid pi2
            type AP
            channel 6 (2437 MHz), width: 20 MHz (no HT), center1: 2437 MHz
            txpower 20.00 dBm
</pre>
    wlxe84e062972c6 是设备名称。phy#1 是指定名称。 type managed 表示它是连接到AP的客户端。
    ifindex 4表示每个连接的端口。
        </section>
<br/><br/>
    <strong>步骤2：检查装置状态</strong>
        <section style="margin-left:4%">
    要检查无线设备是否启动，我们使用以下命令。
<pre style="color:indianred">
    ubuntu@ubuntu:~$ ip link show
    1: lo: &lt;LOOPBACK,UP,LOWER_UP&gt; mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
        link&#x2F;loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    2: eth0: &lt;NO-CARRIER,BROADCAST,MULTICAST,UP&gt; mtu 1500 qdisc fq_codel state DOWN mode DEFAULT group default qlen 1000
        link&#x2F;ether b8:27:eb:aa:5c:cd brd ff:ff:ff:ff:ff:ff
    3: wlxe84e06355627: &lt;BROADCAST,MULTICAST,UP,LOWER_UP&gt; mtu 1500 qdisc mq state UP mode DEFAULT group default qlen 1000
        link&#x2F;ether e8:4e:06:35:56:27 brd ff:ff:ff:ff:ff:ff
    4: wlxe84e062972c6: &lt;NO-CARRIER,BROADCAST,MULTICAST,UP&gt; mtu 1500 qdisc mq state DOWN mode DORMANT group default qlen 1000
        link&#x2F;ether e8:4e:06:29:72:c6 brd ff:ff:ff:ff:ff:ff
</pre>
    输出显示 wlxe84e06355627 为 UP，wlxe84e062972c6 为 DOWN。
        </section>
<br/><br/>
    <strong>步骤3：调出wifi介面</strong>
        <section style="margin-left:4%">
    使用以下命令
<pre style="color:indianred">
    ubuntu@ubuntu:~$ sudo ip link set wlxe84e062972c6 up
</pre>
    这样 ifconfig 就能看到该网卡了 
        </section>
<br/><br/>
    <strong>步骤4：检查连接状态。</strong>
        <section style="margin-left:4%">
    使用以下命令检查连接状态
<pre style="color:indianred">
    ubuntu@ubuntu:~$ iw wlxe84e06355627 link
    Not connected.
</pre>
    要查找检测到的所有WIFI网络，请在终端上键入以下命令。
<pre style="color:indianred">
    ubuntu@ubuntu:~$ sudo iw wlxe84e062972c6 scan 
    BSS 44:1e:98:14:fc:38(on wlxe84e062972c6)
        TSF: 45926313013646 usec (531d, 13:18:33)
        freq: 2412
        beacon interval: 100 TUs
        capability: ESS Privacy ShortPreamble ShortSlotTime (0x0431)
        signal: -64.00 dBm
        last seen: 932 ms ago
        Information elements from Probe Response frame:
        SSID: WeWork
        Supported rates: 12.0* 18.0 24.0* 36.0 48.0 54.0 
        DS Parameter set: channel 1
        Country: CN	Environment: Indoor&#x2F;Outdoor
            Channels [1 - 1] @ 20 dBm
            Channels [6 - 6] @ 20 dBm
            Channels [11 - 11] @ 20 dBm
        ERP: &lt;no flags&gt;
        WMM:	 * Parameter version 1
            * u-APSD
            * BE: CW 15-1023, AIFSN 3
            * BK: CW 15-1023, AIFSN 7
            * VI: CW 7-15, AIFSN 2, TXOP 3008 usec
            * VO: CW 3-7, AIFSN 2, TXOP 1504 usec
        RSN:	 * Version: 1
            * Group cipher: CCMP
            * Pairwise ciphers: CCMP
            * Authentication suites: PSK
            * Capabilities: 1-PTKSA-RC 1-GTKSA-RC (0x0000)
        HT capabilities:
            Capabilities: 0x9ad
                RX LDPC
                HT20
                SM Power Save disabled
                RX HT20 SGI
                TX STBC
                RX STBC 1-stream
                Max AMSDU length: 7935 bytes
                No DSSS&#x2F;CCK HT40
            Maximum RX AMPDU length 65535 bytes (exponent: 0x003)
            Minimum RX AMPDU time spacing: 16 usec (0x07)
            HT RX MCS rate indexes supported: 1-31
            HT TX MCS rate indexes are undefined
        HT operation:
            * primary channel: 1
            * secondary channel offset: no secondary
            * STA channel width: 20 MHz
            * RIFS: 0
            * HT protection: no
            * non-GF present: 0
            * OBSS non-GF present: 0
            * dual beacon: 0
            * dual CTS protection: 0
            * STBC beacon: 0
            * L-SIG TXOP Prot: 0
            * PCO active: 0
            * PCO phase: 0
        BSS Load:
            * station count: 2
            * channel utilisation: 148&#x2F;255
            * available admission capacity: 0 [*32us]
        Extended capabilities:
            * Proxy ARP Service
            * BSS Transition
            * Operating Mode Notification
    BSS 44:1e:98:54:fc:38(on wlxe84e062972c6)
        TSF: 45926313011064 usec (531d, 13:18:33)
        freq: 2412
        beacon interval: 100 TUs
        capability: ESS Privacy ShortPreamble ShortSlotTime (0x0431)
        signal: -64.00 dBm
        last seen: 936 ms ago
        Information elements from Probe Response frame:
        SSID: WeWorkCorp
        Supported rates: 12.0* 18.0 24.0* 36.0 48.0 54.0 
        DS Parameter set: channel 1
        Country: CN	Environment: Indoor&#x2F;Outdoor
            Channels [1 - 1] @ 20 dBm
            Channels [6 - 6] @ 20 dBm
            Channels [11 - 11] @ 20 dBm
        ERP: &lt;no flags&gt;
        WMM:	 * Parameter version 1
            * u-APSD
            * BE: CW 15-1023, AIFSN 3
            * BK: CW 15-1023, AIFSN 7
            * VI: CW 7-15, AIFSN 2, TXOP 3008 usec
            * VO: CW 3-7, AIFSN 2, TXOP 1504 usec
        RSN:	 * Version: 1
            * Group cipher: CCMP
            * Pairwise ciphers: CCMP
            * Authentication suites: IEEE 802.1X
            * Capabilities: 1-PTKSA-RC 1-GTKSA-RC (0x0000)
        HT capabilities:
        .....
</pre>
    以上是wifi扫描结果
        </section>
<br/><br/>
    <strong>步骤5：生成WPA&#x2F;WPA2配置文件</strong>
        <section style="margin-left:4%">
    用于 wpa-supplicant，其中包含所有wifi网络的预共享密钥
<pre style="color:indianred">
    ubuntu@ubuntu:~$ wpa_passphrase WeWork &gt;&gt; &#x2F;etc&#x2F;wpa_supplicant.conf
    123123123
    ubuntu@ubuntu:~$ cat &#x2F;etc&#x2F;wpa_supplicant.conf
    # reading passphrase from stdin
    network={
        ssid=&quot;WeWork&quot;
        #psk=&quot;123123123&quot;
        psk=eff57eb1c15735d72cc38c31b10fabcbe95ed38b820780e5290682a49cf1f3bb
    }
</pre>
    密码长度为8位
        </section>
<br/><br/>
    <strong>步骤6：使用wpa_supplicant连接到WPA&#x2F;WPA2 wifi网络</strong>
        <section style="margin-left:4%">
    使用以下命令
<pre style="color:indianred">
    wpa_supplicant -B -D nl80211 -i wlxe84e062972c6 -c &#x2F;etc&#x2F;wpa_supplicant.conf
</pre>
    -B 在后台运行wpa_supplicant
<br/><br/>
    -D 要使用的驱动程序(可以是多个驱动程序：nl80211，wext)
<br/><br/>
    -i 无线网卡名称
<br/><br/>
    -c 给出配置文件的实际路径
        </section>
<br/><br/>
    <strong>步骤7：从DHCP服务器获取IP地址</strong>
        <section style="margin-left:4%">
    执行命令    
<pre style="color:indianred">
    dhclient wlxe84e062972c6
</pre>
    使用ifconfig命令验证IP地址
<pre style="color:indianred">
    ifconfig -a
</pre>
        </section>
<br/><br/>
    <strong>步骤8：添加默认路由规则以确保您具有正确的路由规则</strong>
<pre style="color:indianred">
    ip route show default via 10.0.0.40 dev wlxe84e062972c6 10.0.0.0&#x2F;24 dev wlxe84e062972c6 proto kernel scope link src 10.0.0.8
</pre>
<br/><br/>
    <strong>步骤9：通过ping到任何全球性IP地址（例如google DNS服务器）来测试连接性。</strong>
        <section style="margin-left:4%">
    执行以下命令
<pre style="color:indianred">
    ping 8.8.8.8
</pre>
        </section>
<br/><br/>
<br/><br/>
<br/><br/>
    </section>
</section>

            </section>
            <style>
                p:first-of-type{
                    margin-bottom: 15px;
                    text-align: center;
                }
                p:first-of-type span:first-child {
                    float: left;
                }
                p:first-of-type span:last-child  {
                    float: right;
                }
            </style>
        </body>
        </html>
        